/*
 * �������� 2006-5-30
 *
 */
package com.jmcgg.freesky.common.util;

import org.apache.log4j.Logger;

/**
 * Title: FreeSky Common Java Library <br>
 * Description: FreeSky Common Java Library <br>
 * Copyright: Copyright (c) 2005~2009 www.afss.cn <br>
 * Company: Amei's FreeSky Studio <br>
 * 
 * @author <b>Jacky Chou</b> (AFSS [Amei's FreeSky Studio])
 * @version 1.2.1, 2008-08-05, Clean and optimize the source code.<br>
 *          1.2.0, 2008-02-23, Upgrade freesky.jar to 1.2.0 with Struts 2<br>
 *          1.0.0, 2006-05-30, Initial Version
 */
public class TypeUtil extends FreeskyUtil {
	/**
	 * Log4J Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(TypeUtil.class);

	public TypeUtil() {
		super();
	}

	public static float str2Float(String str) {
		if (str == null || str.length() < 1) {
			return 0;
		}
		try {
			float f = Float.parseFloat(str.trim());
			return f;
		} catch (Exception e) {
			logger.error("str2Float(String) - String str=" + str, e);
		}
		return 0;
	}

	public static int str2Int(String str) {
		if (str == null || str.length() < 1) {
			return 0;
		}
		try {
			int i = Integer.parseInt(str.trim());
			return i;
		} catch (Exception e) {
			logger.error("str2Int(String) - String str=" + str, e);
		}
		return 0;
	}

	public static int strNum2Int(String str) {
		if (str == null || str.length() < 1) {
			return 0;
		}
		try {
			int i = (int) Double.parseDouble(str.trim());
			return i;
		} catch (Exception e) {
			logger.error("str2Int(String) - String str=" + str, e);
		}
		return 0;
	}

	public static short str2Short(String str) {
		if (str == null || str.length() < 1) {
			return 0;
		}
		try {
			short sh = Short.parseShort(str.trim());
			return sh;
		} catch (Exception e) {
			logger.error("str2Short(String) - String str=" + str, e);
		}
		return 0;
	}

	public static long str2Long(String str) {
		if (str == null || str.length() == 0) {
			return 0;
		}
		try {
			long sh = Long.parseLong(str.trim());
			return sh;
		} catch (Exception e) {
			logger.error("str2Long(String) - String str=" + str, e);
		}
		return 0;
	}
}
